package com.listener.controller;


import com.listener.dao.AbilityDao;
import com.listener.dao.MoveDao;
import com.listener.pojo.Ability;
import com.listener.pojo.Move;
import com.listener.pojo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Controller
public class AbilityController {
    @Autowired
    AbilityDao abilityDao;
    @RequestMapping("/selectAbilityPage")
    public String selectAbilityPage(Ability abilityCondition, Integer pageNum, HttpServletRequest request) throws IOException {
        if(pageNum==null){pageNum=1;}
        //如果条件不为空且不为""记录条件到session
        if(abilityCondition.getAbility()!=null ||
                abilityCondition.getDescription()!=null
        ){
            if (abilityCondition.getAbility()!=null && abilityCondition.getAbility().equals("")) abilityCondition.setAbility(null);
            if (abilityCondition.getDescription()!=null && abilityCondition.getDescription().equals("")) abilityCondition.getDescription();
            request.getSession().setAttribute("abilityCondition",abilityCondition);
        }else {
            if(request.getSession().getAttribute("abilityCondition")!=null){
                abilityCondition= (Ability) request.getSession().getAttribute("abilityCondition");
            }
        }
        Page<Ability> abilityPage =
                abilityDao.selectAbilityPage(abilityCondition,
                        pageNum,20);
        request.setAttribute("abilityPage",abilityPage);
        return "forward:/web/abilityPage.jsp";
    }
}
